package com.tusuo.stds.rest;

import android.text.TextUtils;

import com.tusuo.stds.util.DateUtils;

import org.parceler.Parcel;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author J.Huang
 * @version 1.0
 *
 */

@Parcel
public class LevelResult extends ApiResult {
    public static final String EXTRA_NAME = LevelResult.class.getName();

    public boolean IsPass;          // 是否通过
    public float CorrectRate;       // 正确率,为开始为:0
    public String ThroughTime;      // 通过时间,未开始为：""
    public int ClearanceTime;       // 完成耗时时间，单位：s,未开始为：0
    public int NextLevelId;         // 下一关，关卡Id，不存在值为0
    public int CompletionStatus;    // 完成情况
    public int LevelType;           // 关卡类型
    public List<LevelList.Level> OpenLevelList;
    public List<SceneList.Scene> OpenSceneList;
    public List<GroupItem> GroupList;

    public String getFormattedThroughTime() {
        if (!TextUtils.isEmpty(ThroughTime)) {
            try {
                Date date = new SimpleDateFormat("yyyy/MM/dd HH:mm").parse(ThroughTime);


                if (DateUtils.isToday(date)) {
                    return new SimpleDateFormat("HH:mm").format(date);
                } else if (DateUtils.isYesterday(date)) {
                    return "昨天 " + new SimpleDateFormat("HH:mm").format(date);
                } else if (DateUtils.isThisYear(date)) {
                    return new SimpleDateFormat("MM/dd HH:mm").format(date);
                } else {
                    return ThroughTime;
                }

            } catch (ParseException e) {
                e.printStackTrace();
                return ThroughTime;
            }
        }
        return "";
    }

    @Override
    public String toString() {
        return "LevelResult{" +
                "IsPass=" + IsPass +
                ", CorrectRate=" + CorrectRate +
                ", ThroughTime='" + ThroughTime + '\'' +
                ", ClearanceTime=" + ClearanceTime +
                ", CompletionStatus=" + CompletionStatus +
                ", OpenLevelList=" + OpenLevelList +
                ", OpenSceneList=" + OpenSceneList +
                '}';
    }

    @Parcel
    public static class GroupItem {
        public int Id; // 组合id
        public int Type; // 1 合格 2 模糊 3 问题
        public int OldType;
        public int CorrectCount; // 数量
        public int ErrorCount;
        public String Name; // 组合名称

        @Override
        public String toString() {
            return "GroupItem{" +
                    "Id=" + Id +
                    ", Type=" + Type +
                    ", OldType=" + OldType +
                    ", CorrectCount=" + CorrectCount +
                    ", ErrorCount=" + ErrorCount +
                    ", Name='" + Name + '\'' +
                    '}';
        }
    }

}
